'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

var vue = new Vue({
    data: {
        search: {
            page: 1,
            userid: '',
            username: '',
            groupid: '0',
            truename: ''
        },
        loading: false,
        tableData: [],
        total: 0

    },
    methods: {
        //加载数据
        load_data: function load_data(cb) {
            var _this = this;

            this.loading = true;
            axios.post('/api/member/lst', {
                page: this.search.page,
                userid: this.search.userid,
                username: this.search.username,
                groupid: this.search.groupid,
                truename: this.search.truename
            }).then(function (response) {
                var data = response.data;
                _this.loading = false;
                _this.tableData = data.data.rows;
                _this.total = data.data.total;
                if (cb) {
                    cb();
                }
                _this.$forceUpdate();
            }).catch(function (error) {
                _this.loading = false;
                _this.$message.error(error.toString());
            });
        },

        //分页点击
        handleCurrentChange: function handleCurrentChange(page) {
            this.search.page = page;
            this.load_data();
            this.$paging();
        },

        //搜索
        to_search: function to_search() {
            var c = 0;
            if (parseInt(this.search.userid) > 0) {
                c++;
            }
            if (this.search.username.length > 0) {
                c++;
            }
            if (parseInt(this.search.groupid) > 0) {
                c++;
            }
            if (this.search.truename.length > 0) {
                c++;
            }
            if (!c) {
                this.$message.error('请输入搜索条件！');
                return;
            }
            this.search.page = 1;
            this.load_data();
        },

        //重置
        to_reset: function to_reset() {
            this.search = {
                page: 1,
                userid: '',
                username: '',
                groupid: '0',
                truename: ''
            };
            this.load_data();
        },

        //预览
        handlePreview: function handlePreview(index, row) {
            this.$forward('/admin/member/preview?userid=' + row.userid);
        },

        //编辑
        handleEdit: function handleEdit(index, row) {
            this.$forward('/admin/member/mod?userid=' + row.userid);
        },

        //删除
        handleDelete: function handleDelete(index, row) {
            var _this2 = this;

            this.$confirm('确定要禁用吗？', '系统提醒', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(function () {
                _this2.loading = true;
                axios.post('/api/member/del', { userid: row.userid }).then(function (response) {
                    _this2.loading = false;
                    var data = response.data;
                    if (parseInt(data.code) > 0) {
                        _this2.load_data();
                        _this2.$message({
                            type: 'success',
                            message: '禁用成功!'
                        });
                    } else {
                        _this2.$message({
                            type: 'error',
                            message: '禁用失败!'
                        });
                    }
                }).catch(function (error) {
                    _this2.loading = false;
                    _this2.$message.error(error.toString());
                });
            }).catch(function () {});
        }
    },
    created: function created() {},
    mounted: function () {
        var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
            var search;
            return regeneratorRuntime.wrap(function _callee$(_context) {
                while (1) {
                    switch (_context.prev = _context.next) {
                        case 0:
                            this.$check_login('member', 'lst');

                            //sessionStorage
                            try {
                                if (sessionStorage.hasOwnProperty(location.pathname)) {
                                    search = sessionStorage.getItem(location.pathname);

                                    this.search = JSON.parse(search);
                                }
                            } catch (e) {
                                console.error(e);
                            }
                            //加载数据
                            this.load_data();

                        case 3:
                        case 'end':
                            return _context.stop();
                    }
                }
            }, _callee, this);
        }));

        function mounted() {
            return _ref.apply(this, arguments);
        }

        return mounted;
    }()
}).$mount('#app');